package ru.bytedog.oiot.counter.bot.config;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import ru.bytedog.oiot.counter.bot.service.adapter.LocalDateTimeAdapter;

import java.time.LocalDateTime;

@Component
public class RestIntegrationConfiguration {

    private final LocalDateTimeAdapter timeAdapter;

    public RestIntegrationConfiguration(LocalDateTimeAdapter timeAdapter) {
        this.timeAdapter = timeAdapter;
    }

    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @Bean
    public Gson getJsonMapper() {
        return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, timeAdapter)
                .registerTypeHierarchyAdapter(LocalDateTime.class, timeAdapter)
                .create();
    }
}
